#include "condition.h"
#include "formulaanalyse.h"
#include "easylogging/easylogging++.h"

Condition::Condition()
{
    m_dResult = 1;
}

Condition::~Condition()
{
    for(int i = 0; i < m_vEntitys.size(); i++)
    {
        delete m_vEntitys[i];
    }
}

double Condition::GetResult()
{
    return m_dResult;
}

void Condition::AddEntity(Entity *entity)
{
    m_vEntitys.push_back(entity);
}

ConditionResult Condition::Run(int nRuleID, QString entityName, bool isEnd)
{
    ConditionResult result;
    result.name = m_sConditionName;
    for(int i = 0; i < m_vEntitys.size(); i++)
    {
        Entity* entity = m_vEntitys[i];
        EntityResult entityResult = entity->CheckState(entityName);
        if(!entityResult.result)
        {
            result.entityResults.push_back(entityResult);

            LDEBUG<<"entity check false : " << entity->GetResult();
        }
    }

    result.result = m_dResult = FormulaAnalyse::Result(m_vEntitys,m_sFormula);
    return result;
}
